from flask import Flask, render_template
from flask_socketio import SocketIO, send

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)

# 路由
@app.route('/')
def index():
    return render_template('index.html')

# 接收消息事件
@socketio.on('message')
def handle_message(msg):
    print(f"Received message: {msg}")
    send(msg, broadcast=False)  # 广播给所有客户端

if __name__ == '__main__':
    socketio.run(app, host='0.0.0.0', port=5001)
